package com.yellowcong.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

/**
 * @author yellowcong
 * 创建日期:2018/01/31
 * 编码拦截器
 */
public class PageFilter implements Filter {

	private String pageSize = "10";
	private String pageOrder = "asc";
	
	@Override
	public void destroy() {
		System.out.println("销毁过滤器");
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse resposne, FilterChain filter)
			throws IOException, ServletException {
		HttpServletRequest req = (HttpServletRequest) request;
		System.out.println("sessionId\t"+req.getSession().getId());
		System.out.println("用户ip\t"+req.getRemoteAddr());
		System.out.println("用户名称\t"+req.getRemoteUser());
		System.out.println("请求编码\t"+req.getCharacterEncoding());
		System.out.println("请求访问地址\t"+req.getRequestURI());
		
		
		filter.doFilter(request, resposne);
	}

	@Override
	public void init(FilterConfig filter) throws ServletException {
		
		this.pageSize =filter.getInitParameter("pageSize");
		this.pageOrder = filter.getInitParameter("pageOrder");
		
		System.out.println("画面初期化");
		System.out.println("页面大小\t"+pageSize);
		System.out.println("页面排序方式\t"+pageOrder);
	}
}
